#include <stdio.h>
#include <stdint.h>
#include "driver/gpio.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <esp_log.h>

void init_led()
{
    gpio_config_t io_conf;
    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pin_bit_mask = (1ULL << GPIO_NUM_2);
    io_conf.pull_down_en = 0;
    io_conf.pull_up_en = 0;
    gpio_config(&io_conf);
}

void led_on()
{
    gpio_set_level(GPIO_NUM_2, 1);
}

void led_off() {
    gpio_set_level(GPIO_NUM_2, 0);
}

void led_blink(int count)
{
    int blink_count = 1;

    if (count > 0) {
        blink_count = count;
    }
    for (int i = 0; i < blink_count; i++)
    {
        ESP_LOGI("ESP", "Blink %d,...%d\n", i, blink_count);
        led_on();
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        led_off();
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}